/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2019 HUST Dian Group
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Original Author: Pengyu Liu <eicliupengyu@gmail.com>
 */
#pragma once
#include "robo-actor.h"
#include "singleton-object.h"
#include "robo-weapon.h"
#include "robo-base.h"
#include "robo-ammo.h"

namespace ns3 {
struct RoboInfo
{
  uint8_t uid;
  uint8_t team;
  std::string name;
  RoboType type;
  bool isDied;
};

class RoboBase;
class RoboJudge : public Object, public SingletonObject<RoboJudge>
{
  friend class RoboAmmo;
  friend class RoboBase;
  friend class RoboTeamHelper;

public:
  RoboJudge ();
  ~RoboJudge ();
  static TypeId GetTypeId (void);
  virtual TypeId GetInstanceTypeId (void) const;
  void Init ();
  RoboInfo QueryRobo (uint8_t uid);
  void Resurrection (uint8_t uid, uint8_t target);

private:
  std::vector<Ptr<RoboBase>> m_roboList;
  std::list<Ptr<RoboActor>> m_ammoList;
  std::vector<Ptr<RoboActor>> m_buildingList;
  std::map<uint8_t, std::map<uint8_t, Time>> m_shootTime;

  float m_updatePeroid;
  float m_visibleDistance;
  float m_loseFac;
  bool m_enablePlot;
  float m_plotPeroid;
  FILE *m_plotFp{NULL};
  std::string m_plotFileName;
  uint16_t m_bufferSize;

  float m_boundaryX;
  float m_boundaryY;
  Ptr<UniformRandomVariable> m_random;
  void PlotAll ();
  void CloseFile ();

  void Update ();

  void AddRobo (Ptr<RoboBase> robo);
  void AddAmmo (Ptr<RoboActor> ammo);
  void AddBuilding (Ptr<RoboActor> building);
  bool GiveAmmoTo (uint8_t sourceId, uint8_t targetId, int num, AmmoType ammoType);
  void IndicateShoot (uint8_t shooter, uint8_t target, int injury);
  void IndicateRoboUpgrade (uint8_t uid);
  void IndicateLifeUpgrade (uint8_t uid);
  void IndicateMaxAmmoSpeedUpgrade (uint8_t uid);
  void IndicateKillSelf (uint8_t uid);
};

} // namespace ns3
